package json;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author dakhoa
 * @version 1.0
 */
public class ElementJson extends AbstractJsonObject {

    private String id;
    private String value;
    private String innerHTML;
    private String disabled = "false";
    private String visibled = "true";
    private String clazz;
    private String style;
    private String checked = "false";

    public ElementJson(String id) {
        this.id = id;
    }

    /**
     * 
     * @param id the html element id
     * @param value the html element value
     * @param disabled the html disabled  attribute
     * @param visibled control the visibiliy of html element, this can be also
     * control using style & class
     */
    public ElementJson(String id, String value, String disabled, String visibled) {
        this.id = id;
        this.value = value;
        this.disabled = disabled;
        this.visibled = visibled;
    }

    public String getChecked() {
        return checked;
    }

    public ElementJson setChecked(String checked) {
        this.checked = checked;
        return this;
    }

    public String getClazz() {
        return clazz;
    }

    public ElementJson setClazz(String clazz) {
        this.clazz = clazz;
        return this;
    }

    public String getDisabled() {
        return disabled;
    }

    public ElementJson setDisabled(String disabled) {
        this.disabled = disabled;
        return this;
    }

    public String getId() {
        return id;
    }

    public ElementJson setId(String id) {
        this.id = id;
        return this;
    }

    public String getInnerHTML() {
        return innerHTML;
    }

    public ElementJson setInnerHTML(String innerHTML) {
        this.innerHTML = innerHTML;
        return this;
    }

    public String getStyle() {
        return style;
    }

    public ElementJson setStyle(String style) {
        this.style = style;
        return this;
    }

    public String getValue() {
        return value;
    }

    public ElementJson setValue(String value) {
        this.value = value;
        return this;
    }

    public String getVisibled() {
        return visibled;
    }

    public ElementJson setVisibled(String visibled) {
        this.visibled = visibled;
        return this;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ElementJson other = (ElementJson) obj;
        if ((this.id == null) ? (other.id != null) : !this.id.equals(other.id)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 83 * hash + (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    @Override
    protected Map<String, Object> serializeFields() {
        Map<String, Object> f2Json = new HashMap<String, Object>();

        f2Json.put("id", id);
        f2Json.put("cl", clazz);
        f2Json.put("di", disabled);
        f2Json.put("inn", innerHTML);
        f2Json.put("st", style);
        f2Json.put("va", value);
        f2Json.put("vi", visibled);
        f2Json.put("ch", checked);

        return f2Json;
    }
}
